import {routerRedux} from 'dva/router';
import api from '../api';
import {message} from 'antd'

import { benchListPreset} from '../utils/dataConfig'

export default {
  namespace : 'portfolio',
  state : {
    portList:[],// 产品组合列表 默认值 []
    // lPortId: null,// 产品组合ID 默认值 产品ID排序第一的产品 || query中的 lPortId
    currentPort:null,
    benchList:[],// 业绩基准列表 默认值 []
    // cBenchCode: null,// 业绩基准ID 默认值 沪深300 || query中的 cBenchCode
    currentBench:null,
  },
  effects : {
    * getOnePdt({
    id,payload
  }, {call, put, select}) {
    // 获取指定的产品数据
    const res = yield call(api.getOnePdt, id,payload)
    if (res.code == 0) {
      const currentPort = res.data
      yield put({type: 'setState', payload: {
        currentPort,
        }})
    } else {
      message.info('获取指定的产品数据失败！')
    }
  },
    * getPdtList({
      payload
    }, {call, put, select}) {
      // 获取产品列表数据：term
      const res = yield call(api.getpdtList, payload)
      if (res.code == 0) {
        const portList = res.data
        yield put({type: 'setState', payload: {
          portList,
          }})
      } else {
        message.info('获取产品列表数据失败！')
      }
    },
    * getOneBench({
    id,payload
  }, {call, put, select}) {
    // 获取指定的产品数据
    const res = yield call(api.getOnePdt, id,payload)
    if (res.code == 0) {
      const currentBench = res.data
      yield put({type: 'setState', payload: {
        currentBench,
        }})
    } else {
      message.info('获取指定的产品数据失败！')
    }
  },
    * getBenchList({
    payload
  }, {call, put, select}) {
    // 获取基准列表数据：term
    const res = yield call(api.benchmarkMgt.getBenchmark, payload)
    if (res.code == 0) {
      const benchList = res.data
      console.log(34221111,benchList)
      yield put({type: 'setState', payload: {
        benchList,
        }})
    } else {
      message.info('获取基准列表数据失败！')
    }
  },
  * getBenchListN({
    payload
  }, {call, put, select}) {
    // 获取基准列表数据：term
    const res = yield call(api.benchmarkMgt.getBenchmarks, payload)
    if (res.code == 0) {
      const benchmarksList = []
      const data = res.data;
      data.map((i)=>{
        i.benchList.map((k)=>{
          benchmarksList.push(k)
        })
      })
      const benchList = benchmarksList
      yield put({type: 'setState', payload: {
        benchList,
        }})
    } else {
      message.info('获取基准列表数据失败！')
    }
  },
  },
  reducers : {
    setState(state, {payload}) {
      return {
        ...state,
        ...payload
      }
    }
  }
}
